<?php

namespace api\modules\V1\modules\Activity\controllers;

use common\models\c2\rest\Activity;
use common\rest\statics\ResponseDatum;

/**
 * Default controller for the `activity` module
 */
class DefaultController extends \common\rest\controllers\Controller
{

    public $modelClass = 'common\models\c2\entity\ActivityModel';

    /**
     * Renders the index view for the module
     * @return array
     */
    public function actionIndex()
    {
        $modelClass = $this->modelClass;
        $params = \Yii::$app->request->get();
        $model = $modelClass::findOne($this->rebuildParams($params));
        if (is_null($model)) {
            return ResponseDatum::getErrorDatum(['message' => \Yii::t('app.c2', 'Activity Disabled')], false);
        }
        return ResponseDatum::getSuccessDatum([], $model);
    }

    public function rebuildParams($params) {
        if (isset($params['id'])) {
            return $params['id'];
        }
        if (isset($params['c'])) {
            return ['seo_code' => $params['c']];
        }
        return [];
    }


}
